package com.app.bimo.module_accounts.mvp.persenter;


import com.alibaba.android.arouter.launcher.ARouter;
import com.app.bimo.commonbusiness.mvp.BasePresenter;
import com.app.bimo.commonbusiness.network.RxObservableUtil;
import com.app.bimo.commonbusiness.util.LoginService;
import com.app.bimo.commonbusiness.util.RouterHub;
import com.app.bimo.module_accounts.mvp.constract.PreferenceNextContract;
import com.app.bimo.module_accounts.mvp.model.entiy.TagData;

import java.util.List;

public class PreferenceNextPresenter extends BasePresenter<PreferenceNextContract.Model, PreferenceNextContract.View> {
    public PreferenceNextPresenter(PreferenceNextContract.Model model, PreferenceNextContract.View rootView) {
        super(model, rootView);

    }


    public void getTags(int page, int pageSize) {
        RxObservableUtil.subscribe(mModel.getTags(page, pageSize, ""), bindCustomLoadingLifecycle(true), bookStoreDataList -> {
            /**
             * 断网后点击重试  需要dialog  获取数据成功后 消失
             */
            mRootView.notifyTags(bookStoreDataList);
        }, e -> {

        });
    }

    public void getTags(int page, int pageSize, String tagName) {
        RxObservableUtil.subscribe(mModel.getTags(page, pageSize, tagName), bindCustomLifecycle(), bookStoreDataList -> {
            /**
             * 断网后点击重试  需要dialog  获取数据成功后 消失
             */
            mRootView.notifySearchTags(bookStoreDataList, tagName);
        }, e -> {
        });
    }

    public void setTags(List<TagData> list) {
        if (list == null || list.size() == 0) {
            return;
        }
        String ids = "";
        for (int i = 0; i < list.size(); i++) {
            if (i < list.size() - 1) {
                ids = ids + list.get(i).getTagid() + ",";
            } else {
                ids = ids + list.get(i).getTagid();
            }
        }
        RxObservableUtil.subscribe(mModel.setTags(ids), bindCustomLoadingLifecycle(true), bookStoreDataList -> {
            /**
             * 断网后点击重试  需要dialog  获取数据成功后 消失
             */
            mRootView.notifySetTags();
        });
    }

    public void getUsedTags() {
        RxObservableUtil.subscribe(mModel.getUsedTags(), bindCustomLifecycle(), bookStoreDataList -> {
            /**
             * 断网后点击重试  需要dialog  获取数据成功后 消失
             */
            mRootView.notifyUsedTags(bookStoreDataList);
        });
    }


    public void setPreFromModel(int channel, String ids) {
        RxObservableUtil.subscribe(mModel.setPre(channel, ids)
                , bindCustomLoadingLifecycle(true)
                , bookStoreDataList -> {
                    // 处理数据 直接获取到List<JavaBean> carBeans
                    mRootView.setPreDataNotify();
                    mRootView.hideDialogLoading();
                    ((LoginService) ARouter.getInstance().build(RouterHub.ACCOUNT_SERVICE).navigation()).getUserInfo();
                });
    }
}
